#include "MelodyCrossover.h"
#include "RandomNumberGenerator.h"
#include "MelodyCandidate.h"

MelodyCrossover::MelodyCrossover(int numCrossovers)
    : Crossover(numCrossovers)
{
}

std::vector<Candidate*> MelodyCrossover::mate(Candidate* parent1, Candidate* parent2) {
   result.clear();
   Candidate* offspring1 = new MelodyCandidate();
   Candidate* offspring2 = new MelodyCandidate();
   offspring1->clone(parent1);
   offspring2->clone(parent2);
   for (int i = 0; i < numCrossovers; i++) {
      //int crossoverIndex = (1 + RandomNumberGenerator::nextInt( parent1->getLength() -1));
      offspring1->swapSubString(offspring2,0);
   }
   result.push_back(offspring1);
   result.push_back(offspring2);
   return result;
}
